using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsGame1.CoreComponents;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using WindowsGame1.SpriteClasses;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Audio;


namespace WindowsGame1
{
    class ActionScreen : GameScreen
    {
        //Texture2D characterHUDTexture;
        string tilesetName;
        Tileset tileset;
        int viewportWidth;
        int viewportHeight;
        TileMapComponent tileMapComponent;
        TileMap tileMap;

        public ActionScreen(Game game, SpriteFont gameFont, TileMap tileMap, string
        tilesetName)
            : base((Game1)game)
        {
            this.tilesetName = tilesetName;
            this.tileMap = tileMap;
            LoadContent();
            tileMapComponent = new TileMapComponent(tileMap, tileset, game);
            Components.Add(tileMapComponent);
            tileMapComponent.Show();
            viewportWidth = TileEngine.ViewPortWidth;
            viewportHeight = TileEngine.ViewPortHeight;
            
        }

        protected override void LoadContent()
        {
            base.LoadContent();
            tileset = Content.Load<Tileset>(@"TileSets\" + tilesetName);
            
        }

        public bool CheckUnWalkableTile(Rectangle bounds, Vector2 motion)
        {
            Rectangle nextRectangle = new Rectangle(
            bounds.X + (int)motion.X,
            bounds.Y + (int)motion.Y,
            bounds.Width,
            bounds.Height);
            if (motion.Y < 0 && motion.X < 0)
            {
                return tileMap.CheckUpAndLeft(nextRectangle);
            }
            else if (motion.Y < 0 && motion.X == 0)
            {
                return tileMap.CheckUp(nextRectangle);
            }
            else if (motion.Y < 0 && motion.X > 0)
            {
                return tileMap.CheckUpAndRight(nextRectangle);
            }
            else if (motion.Y == 0 && motion.X < 0)
            {
                return tileMap.CheckLeft(nextRectangle);
            }
            else if (motion.Y == 0 && motion.X > 0)
            {
                return tileMap.CheckRight(nextRectangle);
            }
            else if (motion.Y > 0 && motion.X < 0)
            {
                return tileMap.CheckDownAndLeft(nextRectangle);
            }
            else if (motion.Y > 0 && motion.X == 0)
            {
                return tileMap.CheckDown(nextRectangle);
            }
            return tileMap.CheckDownAndRight(nextRectangle);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            //if (Visible)
            //{
            //    Vector2 position = new Vector2(0, 0);
            //    position.Y = viewportHeight;
            //    spriteBatch.Draw(characterHUDTexture, position, Color.White);
            //}
        }
        public override void Show()
        {
            base.Show();
            Enabled = true;
            Visible = true;
        }
        public override void Hide()
        {
            base.Hide();
            Enabled = false;
            Visible = false;
        }
    }
}